package com.shiku.imserver.common.ws;

import com.shiku.imserver.common.packets.ImPacket;
import java.util.Arrays;
import org.tio.websocket.common.Opcode;

public class WsPacket extends ImPacket {
    public static final String CHARSET_NAME = "utf-8";
    public static final int MAX_BODY_LENGTH = 524288;
    public static final int MAX_LENGTH_OF_BODY = 2202009;
    public static final int MINIMUM_HEADER_LENGTH = 2;
    private static final long serialVersionUID = 4506947563506841436L;
    private byte[] body;
    private byte[][] bodys;
    private boolean isHandShake;
    private long wsBodyLength;
    private String wsBodyText;
    private boolean wsEof;
    private boolean wsHasMask;
    private byte[] wsMask;
    private Opcode wsOpcode;

    public WsPacket() {
        this.isHandShake = false;
        this.wsOpcode = Opcode.BINARY;
        this.isHandShake = false;
        this.wsOpcode = Opcode.BINARY;
    }

    public WsPacket(short command, byte[] body2) {
        this.isHandShake = false;
        this.wsOpcode = Opcode.BINARY;
        this.isHandShake = false;
        this.wsOpcode = Opcode.BINARY;
        if (body2 == null) {
            setCommand(command);
            setBytes(body2);
            return;
        }
        byte[] imBody = new byte[(body2.length + 1)];
        imBody[0] = (byte) command;
        System.arraycopy(body2, 0, imBody, 1, body2.length);
        setCommand(command);
        setBytes(imBody);
    }

    public void setWSBytes(byte[] bytes) {
        byte cmdBytes = Arrays.copyOf(bytes, 1)[0];
        byte[] contentBytes = Arrays.copyOfRange(bytes, 1, bytes.length);
        setCommand((short) cmdBytes);
        this.bytes = contentBytes;
    }

    public WsPacket(byte[] body2) {
        this();
        this.body = body2;
    }

    public byte[] getBody() {
        return this.body;
    }

    public long getWsBodyLength() {
        return this.wsBodyLength;
    }

    public String getWsBodyText() {
        return this.wsBodyText;
    }

    public byte[] getWsMask() {
        return this.wsMask;
    }

    public Opcode getWsOpcode() {
        return this.wsOpcode;
    }

    public boolean isHandShake() {
        return this.isHandShake;
    }

    public boolean isWsEof() {
        return this.wsEof;
    }

    public boolean isWsHasMask() {
        return this.wsHasMask;
    }

    public String logstr() {
        return "websocket";
    }

    public void setBody(byte[] body2) {
        this.body = body2;
    }

    public void setHandShake(boolean isHandShake2) {
        this.isHandShake = isHandShake2;
    }

    public void setWsBodyLength(long wsBodyLength2) {
        this.wsBodyLength = wsBodyLength2;
    }

    public void setWsBodyText(String wsBodyText2) {
        this.wsBodyText = wsBodyText2;
    }

    public void setWsEof(boolean wsEof2) {
        this.wsEof = wsEof2;
    }

    public void setWsHasMask(boolean wsHasMask2) {
        this.wsHasMask = wsHasMask2;
    }

    public void setWsMask(byte[] wsMask2) {
        this.wsMask = wsMask2;
    }

    public void setWsOpcode(Opcode wsOpcode2) {
        this.wsOpcode = wsOpcode2;
    }

    public byte[][] getBodys() {
        return this.bodys;
    }

    public void setBodys(byte[][] bodys2) {
        this.bodys = bodys2;
    }
}
